﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GrayParrot.Web.Controls.Datatables.Filters
{
    public class DateRange
    {
        public DateTime Start { get; set; }
        public DateTime End { get; set; }

        public bool IsRange
        {
            get 
            {
                return ((Start!=default(DateTime)) && (End != default(DateTime)));
            }
        }

        public DateRange()
	    {
	    }
    }

    public static class DateFilterHelper
    {
        public static DateRange GetDateValue(string value)
        {
            //14/12/2016-yadcf_delim-06/12/2016
            DateRange retValue = new DateRange();

            if (value.ToLower().Contains("-yadcf_delim-"))
            {
                string[] m_dates = value.Split(new string[] { "-yadcf_delim-" }, StringSplitOptions.RemoveEmptyEntries);

                if (m_dates.Length == 2)
                {
                    retValue.Start = DateTime.Parse(m_dates[0]);
                    retValue.End = DateTime.Parse(m_dates[1]);
                }
            }
            else
            {
                retValue.Start = DateTime.Parse(value);
            }

            return retValue;
        }
    }
}
